/**
 * Manejador de ventanas para enviar archivos
 * 
 * @author Carlos Enrique Peña Albarran
 * @version 1.0.0
 * @package SaGem.system.js.nomina
 */



if ((typeof YAHOO !== "undefined") && (YAHOO.util) && (YAHOO.util.Event)) {
	YAHOO.util.Event.throwErrors = true;
}

function limpiar() {
	frmBuscar.txtBuscar.value = "";
}
function llenar() {
	if (frmBuscar.txtBuscar.value == "") {
		frmBuscar.txtBuscar.value = "C&eacute;dula o Contrato";
	}
}





YAHOO.namespace("example.container");

YAHOO.util.Event.onDOMReady(function() {

	// Define various event handlers for Dialog
		var handleSubmit = function() {
			this.submit();
		};
		
		
		var handleCancel = function() {
			this.cancel();
		};
		
		
		var handlePrint = function() {
			alert("Estas seguro que amas a yasmin");
		};
		
		
		var handleSuccess = function(o) {
			var response = o.responseText;
			response = response.split("<!")[0];
			document.getElementById("resp").innerHTML = response;
		};
		var handleFailure = function(o) {
			alert("Submission failed: " + o.status);
		};

		var renviar = function() {
			if (frmRegistrarse.codigo.value != 'Err') {
				if (frmRegistrarse.vclave.value != 'Err') {
					if (frmRegistrarse.vcorreo.value != 'Err') {
						frmRegistrarse.submit();
					} else {
						RReporte.innerHTML = "<div class='reporte'><font style='font-family: Arial, verdana, sans-serif; font-size: 11px;color: #ba1414' > &nbsp; (*) Debe Verificar El Correo</font></div>";
						Effect.Appear('RReporte');
					}
				} else {
					RReporte.innerHTML = "<div class='reporte'><font style='font-family: Arial, verdana, sans-serif; font-size: 11px;color: #ba1414' > &nbsp; (*) Debe Verificar la Clave</font></div>";
					Effect.Appear('RReporte');
				}
			} else {
				RReporte.innerHTML = "<div class='reporte'><font style='font-family: Arial, verdana, sans-serif; font-size: 11px;color: #ba1414' > &nbsp; (*) Debe Verificar la C&eacute;dula</font></div>";
				Effect.Appear('RReporte');
			}
		};

		var enviar = function() {
			Effect.Appear('dtActualizar');
			YAHOO.example.container.dtpersonales.hide();
			new Ajax.Updater(
					'dtActualizar',
					'http://localhost/SaGem/index.php/sagem/actualizar_empleado',
					{
						method : 'post',
						postBody : 'cedula=' + document.all("txtCedula").value
								+ '&nombre=' + document.all("txtNombre1").value
								+ '&nombre2='
								+ document.all("txtNombre2").value
								+ '&apellido='
								+ document.all("txtApellido1").value
								+ '&apellido2='
								+ document.all("txtApellido2").value + '&sexo='
								+ document.all("txtSexo").value + '&edocivil='
								+ document.all("txtEdocivil").value
								+ '&fevida='
								+ document.all("txtFedeVida").value
								+ '&titular='
								+ document.all("txtTitular").value
								+ '&copia_ci=' + document.all("txtCopia").value
								+ '&direccion='
								+ document.all("txtDireccion").value
								+ '&telefono='
								+ document.all("txtTelefono").value
								+ '&nivelacademico='
								+ document.all("txtNivelAcademico").value
								+ '&copia_ba=' + document.all("txtLib").value
								+ '&nacionalidad='
								+ document.all("txtNacionalidad").value
								+ '&ciudad=' + document.all("txtCiudad").value
								+ '&banco='
								+ document.all("txtNombreBanco").value
								+ '&cuenta='
								+ document.all("txtNumeroCta_Bancaria").value
								+ '&dia='
								+ document.all("txtDiaNacimiento").value
								+ '&mes='
								+ document.all("txtMesNacimiento").value
								+ '&ano='
								+ document.all("txtAnoNacimiento").value
					}

			);
		};

		YAHOO.util.Dom.removeClass("dialog1", "yui-pe-content");
		YAHOO.util.Dom.removeClass("dtpersonales", "yui-pe-content");
		YAHOO.util.Dom.removeClass("pnomina", "yui-pe-content");
		YAHOO.util.Dom.removeClass("ccontrasena", "yui-pe-content");
		YAHOO.util.Dom.removeClass("mregistrar", "yui-pe-content");
		YAHOO.util.Dom.removeClass("mrecuperar", "yui-pe-content");
		YAHOO.util.Dom.removeClass("mreclamos", "yui-pe-content");

		// Instancia del Dialogo Archivo
		YAHOO.example.container.dialog1 = new YAHOO.widget.Dialog("dialog1", {
			modal : true,
			width : "35em",
			fixedcenter : true,
			visible : false,
			constraintoviewport : true,
			buttons : [ {
				text : "Enviar",
				handler : handleSubmit,
				isDefault : true
			}, {
				text : "Cancelar",
				handler : handleCancel
			} ]
		});
		/*
		 * Datos Personales
		 */
		YAHOO.example.container.dtpersonales = new YAHOO.widget.Dialog(
				"dtpersonales", {
					modal : true,
					width : "45em",
					fixedcenter : true,
					visible : false,
					constraintoviewport : true,
					buttons : [ {
						text : "Actualizar",
						handler : enviar,
						isDefault : true
					}, {
						text : "Imp. Ficha",
						handler : handlePrint
					}, {
						text : "Cancelar",
						handler : handleCancel
					}  ]
				});
		YAHOO.example.container.mregistrar = new YAHOO.widget.Dialog(
				"mregistrar", {
					modal : true,
					width : "35em",
					fixedcenter : true,
					visible : false,
					constraintoviewport : true,
					buttons : [ {
						text : "Acepto",
						handler : renviar,
						isDefault : true
					}, {
						text : "Cancelar",
						handler : handleCancel
					} ]
				});
		/*
		 * Imprimir Nomina (PNomina)
		 */
		YAHOO.example.container.pnomina = new YAHOO.widget.Panel("pnomina", {
			modal : true,
			width : "32em",
			fixedcenter : true,
			visible : false,
			constraintoviewport : true
		});
		/*
		 * Recuperar Clave
		 */
		YAHOO.example.container.mrecuperar = new YAHOO.widget.Dialog(
				"mrecuperar", {
					modal : true,
					width : "32em",
					fixedcenter : true,
					visible : false,
					constraintoviewport : true,
					buttons : [ {
						text : "Reiniciar",
						handler : renviar,
						isDefault : true
					}, {
						text : "Cancelar",
						handler : handleCancel
					} ]
				});

		/*
		 * Reclamos Clave
		 */
		YAHOO.example.container.mreclamos = new YAHOO.widget.Dialog(
				"mreclamos", {
					modal : true,
					width : "32em",
					fixedcenter : true,
					visible : false,
					constraintoviewport : true,
					buttons : [ {
						text : "Enviar",
						handler : renviar,
						isDefault : true
					}, {
						text : "Cancelar",
						handler : handleCancel
					} ]
				});	
		
		/*
		 * Imprimir cambiar_contrasena (CContrasena)
		 */
		YAHOO.example.container.ccontrasena = new YAHOO.widget.Panel(
				"ccontrasena", {
					modal : true,
					width : "28em",
					fixedcenter : true,
					visible : false,
					constraintoviewport : true

				});

		/*
		 * Funcion de validacion
		 * 
		 */
		YAHOO.example.container.dialog1.validate = function() {
			var data = this.getData();
			if (data.txtArchivo == "") {
				alert("Debe seleccionar al menos un archivo");
				return false;
			} else {
				return true;
			}
		};

		var kl1 = new YAHOO.util.KeyListener(document, {
			keys : 27
		}, {
			fn : YAHOO.example.container.dialog1.hide,
			scope : YAHOO.example.container.dialog1,
			correctScope : true
		});

		kl1.enable();

		var kl2 = new YAHOO.util.KeyListener(document, {
			ctrl : true,
			alt : true,
			keys : 65
		}, {
			fn : YAHOO.example.container.dialog1.show,
			scope : YAHOO.example.container.dialog1,
			correctScope : true
		});

		kl2.enable();

		/* Rutas */

		// Llamadas de procesos
		YAHOO.example.container.dialog1.callback = {
			success : handleSuccess,
			failure : handleFailure
		};

		YAHOO.example.container.dtpersonales.callback = {
			success : handleSuccess,
			failure : handleFailure
		};

		YAHOO.example.container.mregistrar.callback = {
			success : handleSuccess,
			failure : handleFailure
		};
		// Mostrar Dialogos Generales todos los menus.

		YAHOO.example.container.dialog1.render();
		YAHOO.example.container.dtpersonales.render();
		YAHOO.example.container.pnomina.render();
		YAHOO.example.container.ccontrasena.render();
		YAHOO.example.container.mregistrar.render();
		YAHOO.example.container.mrecuperar.render();
		YAHOO.example.container.mreclamos.render();

		YAHOO.util.Event.addListener("show", "click",
				YAHOO.example.container.dialog1.show,
				YAHOO.example.container.dialog1, true);
		YAHOO.util.Event.addListener("hide", "click",
				YAHOO.example.container.dialog1.hide,
				YAHOO.example.container.dialog1, true);

		// -------------------------------------------
		YAHOO.util.Event.addListener("MRegistrar", "click",
				YAHOO.example.container.mregistrar.show,
				YAHOO.example.container.mregistrar, true);
		
		YAHOO.util.Event.addListener("MRecuperar", "click",
				YAHOO.example.container.mrecuperar.show,
				YAHOO.example.container.mrecuperar, true);
		
		YAHOO.util.Event.addListener("MReclamos", "click",
				YAHOO.example.container.mreclamos.show,
				YAHOO.example.container.mreclamos, true);
		
		YAHOO.util.Event.addListener("ORegistrar", "click",
				YAHOO.example.container.mregistrar.hide,
				YAHOO.example.container.mregistrar, true);

		YAHOO.util.Event.addListener("showClave", "click",
				YAHOO.example.container.ccontrasena.show,
				YAHOO.example.container.ccontrasena, true);
		YAHOO.util.Event.addListener("hideClave", "click",
				YAHOO.example.container.ccontrasena.hide,
				YAHOO.example.container.ccontrasena, true);

		// -------------------------------------------
		YAHOO.util.Event.addListener("show_nomina", "click",
				YAHOO.example.container.pnomina.show,
				YAHOO.example.container.pnomina, true);
		YAHOO.util.Event.addListener("hide_nomina", "click",
				YAHOO.example.container.pnomina.hide,
				YAHOO.example.container.pnomina, true);
		//

		YAHOO.util.Event.addListener("show_dtpersonales", "click",
				YAHOO.example.container.dtpersonales.show,
				YAHOO.example.container.dtpersonales, true);
		YAHOO.util.Event.addListener("hide_dtpersonales", "click",
				YAHOO.example.container.dtpersonales.hide,
				YAHOO.example.container.dtpersonales, true);
	});
